package com.ruoyi.web.controller.system;  

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.CaseJudicial;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CaseCardDetails;
import com.ruoyi.system.service.ICaseCardDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案件详情信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-25
 */
@RestController
@RequestMapping("/system/caseDetails")
public class CaseCardDetailsController extends BaseController
{
    @Autowired
    private ICaseCardDetailsService caseCardDetailsService;

    /**
     * 查询案件详情信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:caseDetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(CaseCardDetails caseCardDetails)
    {
        startPage();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String dbDate = LocalDate.now().format(formatter);
        List<CaseCardDetails> list = caseCardDetailsService.selectCaseCardDetailsList(caseCardDetails,dbDate);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:caseDetails:list')")
    @GetMapping("/listJud")
    public TableDataInfo listJud(CaseJudicial caseJudicial)
    {
        startPage();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String dbDate = LocalDate.now().format(formatter);
        List<CaseJudicial> list = caseCardDetailsService.selectCaseJudicialList(caseJudicial,dbDate);
        return getDataTable(list);
    }

    /**
     * 导出案件详情信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:caseDetails:export')")
    @Log(title = "案件详情信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseCardDetails caseCardDetails)
    {
        List<CaseCardDetails> list = (List<CaseCardDetails>) list(caseCardDetails).getRows();
        ExcelUtil<CaseCardDetails> util = new ExcelUtil<CaseCardDetails>(CaseCardDetails.class);
        util.exportExcel(response, list, "案件详情信息数据");
    }

    /**
     * 导出案件详情信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:caseDetails:export')")
    @Log(title = "案件详情信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportJud")
    public void exportJud(HttpServletResponse response, CaseJudicial caseJudicial)
    {
        List<CaseJudicial> list = (List<CaseJudicial>) listJud(caseJudicial).getRows();
        ExcelUtil<CaseJudicial> util = new ExcelUtil<CaseJudicial>(CaseJudicial.class);
        util.exportExcel(response, list, "案件详情信息数据");
    }


    /**
     * 获取案件详情信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:caseDetails:query')")
    @PostMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(caseCardDetailsService.selectCaseCardDetailsById(id));
    }

    /**
     * 新增案件详情信息
     */
    @PreAuthorize("@ss.hasPermi('system:caseDetails:add')")
    @Log(title = "案件详情信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseCardDetails caseCardDetails)
    {
        return toAjax(caseCardDetailsService.insertCaseCardDetails(caseCardDetails));
    }

    /**
     * 修改案件详情信息
     */
    @PreAuthorize("@ss.hasPermi('system:caseDetails:edit')")
    @Log(title = "案件详情信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaseCardDetails caseCardDetails)
    {
        return toAjax(caseCardDetailsService.updateCaseCardDetails(caseCardDetails));
    }

    /**
     * 删除案件详情信息
     */
    @PreAuthorize("@ss.hasPermi('system:caseDetails:remove')")
    @Log(title = "案件详情信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(caseCardDetailsService.deleteCaseCardDetailsByIds(ids));
    }
}
